<template>
  <div>
    <el-form ref="form" :model="formData" :rules="rules" label-width="100px">
      <el-form-item label="组名" prop="title">
        <el-input v-model="formData.title" placeholder="请输入组名"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { update } from '@/api/equipment/group.js';
export default {
  props:['data'],
  watch:{
    data:{
      handler:function(val){
        if(val){
          this.formData.title = val.title
          this.formData.id = val.id
        }
      },
      immediate:true
    }
  },
  data() {
    return {
      formData: {
        title: '',
        id:''
      },
      rules: {
        title: [{ required: true, message: '请输入组名' }],
      },
    };
  },
  methods: {
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          update(this.formData).then((res) => {
            this.$emit("success")
          });
        }
      });
    },
  },
};
</script>

<style scoped></style>
